import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import qxz from './qxz';
import zx from './zx';
import gw from "./gw";
import xxy from "./xxy";
import store from "../store";

import mergeRouter from "../utils/settings/mergeRouter";

console.log("mergeRouter",mergeRouter())
const mergeRouterHandle = []; 
 mergeRouter().map((item)=>{
	console.log(item.path)
		item.path = '/'+ item.path
		mergeRouterHandle.push(item)
	// if(item.path.indexof('/')!==-1){
		// 
	// }
})

// const Home = resolve => require(['../Home'], resolve);
// const RealIndex = resolve => require(['../containers/Index'], resolve);
// const Test2 = resolve => require(['../containers/Test2'], resolve);
// const StyleIndex = resolve => require(['../style-containers/Index'], resolve);
const Main = resolve => require(['../Main.vue'], resolve);
const Closed = resolve => require(['../containers/Closed'], resolve);
Vue.use(Router)
// let router = new Router({
// 	routes: [
// 		{
// 			path: '/',
// 			name: 'HelloWorld',
// 			component: HelloWorld
// 		},
//         ...qxz,
// 		...zx,
// 		...gw,
// 		...xxy,
// 		...mergeRouter()
// 	]
// });
// console.log('router->', router);
// //将一进入的path作为originPath，作为是否退出webview的标志
// (() => {
// 	// console.log("一进入页面的path", location.hash);
// 	try {
// 		if (location.hash.includes("?")) {
// 			store.commit("gw/setOriginPath", location.hash.match(/#(\/.+)\?/)[1]);
// 		} else {
// 			//slice是前闭后开的[start, end)
// 			store.commit("gw/setOriginPath", location.hash.slice(1));
// 		}
// 	} catch (err) {
// 		alert("设置原始路径出错！");
// 	}
	
// })();
// router.beforeEach((to, from, next) => {
// 	console.log("打印from和to", from ,to);
// 	//设置当前路径，取to的path
// 	store.commit("gw/setCurrentPath", to.path);
// 	next();
// });

// export default router;

let routers = {
}
console.log("初始化路由");
routers["ProductionRouter"] = new Router({
	routes: [
		{
			path: '/',
			redirect: {name: "main"}
		},
		//主区域界面
		{
			path: '/main',
			name: 'main',
			redirect: {name: "home"},
			component: Main,
			//主区域界面下的每个页面
			// children: [
			// 	...zx,
			// 	...gw,
			// 	...xxy,
			// 	...qxz,
			// 	...mergeRouter()
			// ]
		},
			...zx,
			...gw,
			...xxy,
			...qxz,
			...mergeRouterHandle
	]
});

routers["ProductionRouter"].beforeEach((to, from, next) => {
	console.log("打印from和to", from ,to);
	//设置当前路径，取to的path
	store.commit("gw/setCurrentPath", to.path);
	next();
});
routers.closed = new Router({
	routes: [
		{
			path: '/',
			component: Closed
		}
	]
});
console.log("打印路由结构", routers);

export default {
	...routers
}